/*
 * Copyright (c) 2025 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#import "ViewController.h"
#import <moduledemo_windows/EntryEntryAbilityViewController.h>

#define BUNDLE_NAME @"com.cjmp.hao.moduledemoWindows"

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    self.view.backgroundColor = [UIColor whiteColor];
    self.title = @"应用首页";

    [self setupKeelsButton];
}

- (void)setupKeelsButton {
    UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
    button.frame = CGRectMake(0, 0, 200, 50);
    button.center = self.view.center;
    [button setTitle:@"进入Keels页面" forState:UIControlStateNormal];
    button.titleLabel.font = [UIFont systemFontOfSize:18 weight:UIFontWeightBold];
    button.backgroundColor = [UIColor systemBlueColor];
    [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    button.layer.cornerRadius = 8;

    // add touch event
    [button addTarget:self action:@selector(openKeelsPage) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:button];
}
- (void)openKeelsPage {
    // create Keels page instance
    NSString *instanceName = [NSString stringWithFormat:@"%@:%@:%@", BUNDLE_NAME, @"entry", @"EntryAbility"];
    EntryEntryAbilityViewController *keelsVC = [[EntryEntryAbilityViewController alloc] initWithInstanceName:instanceName];

    keelsVC.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]
        initWithTitle:@"返回"
                style:UIBarButtonItemStylePlain
               target:self
               action:@selector(backToHome)];

    // jump to keels page
    [self.navigationController pushViewController:keelsVC animated:YES];
}

- (void)backToHome {
    // return to home page
    [self.navigationController popViewControllerAnimated:YES];
}
@end
